From f97579a2c9a4411c67020ae598423ff5470ccf42 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 26 Jun 2015 15:51:53 -0700 Subject: [PATCH] Get `make test` working on MSVC This commit updates Cargo's unit tests to pass `make check` entirely on MSVC targets. Two tests are ignored on MSVC as it requires panicking to be implemented, which currently isn't, but otherwise Cargo is fully functional. --- tests/test_cargo_bench.rs | 1 + tests/test_cargo_compile.rs | 41 +++++++---------------------- tests/test_cargo_compile_plugins.rs | 4 ++- tests/test_cargo_test.rs | 4 ++- tests/tests.rs | 5 ++++ 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 4c3a9f19d..9d0123ec6 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -154,6 +154,7 @@ test!(many_similar_names { test!(cargo_bench_failing_test { if !::is_nightly() { return } + if !::can_panic() { return } let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 02cfa2664..eb4c49359 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -722,24 +722,12 @@ test!(many_crate_types_old_style_lib_location { .file("src/foo.rs", r#" pub fn foo() {} "#); - assert_that(p.cargo_process("build"), - execs().with_status(0)); + assert_that(p.cargo_process("build"), execs().with_status(0)); - let files = fs::read_dir(&p.root().join("target/debug")).unwrap(); - let mut files: Vec = files.map(|e| e.unwrap().path()).filter_map(|f| { - match f.file_name().unwrap().to_str().unwrap() { - "build" | "examples" | "deps" => None, - s if s.contains("fingerprint") || s.contains("dSYM") => None, - s => Some(s.to_string()) - } - }).collect(); - files.sort(); - let file0 = &files[0]; - let file1 = &files[1]; - println!("{} {}", file0, file1); - assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib")); - assert!(file0.ends_with(env::consts::DLL_SUFFIX) || - file1.ends_with(env::consts::DLL_SUFFIX)); + assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file()); + let fname = format!("{}foo{}", env::consts::DLL_PREFIX, + env::consts::DLL_SUFFIX); + assert_that(&p.root().join("target/debug").join(&fname), existing_file()); }); test!(many_crate_types_correct { @@ -763,21 +751,10 @@ test!(many_crate_types_correct { assert_that(p.cargo_process("build"), execs().with_status(0)); - let files = fs::read_dir(&p.root().join("target/debug")).unwrap(); - let mut files: Vec = files.map(|f| f.unwrap().path()).filter_map(|f| { - match f.file_name().unwrap().to_str().unwrap() { - "build" | "examples" | "deps" => None, - s if s.contains("fingerprint") || s.contains("dSYM") => None, - s => Some(s.to_string()) - } - }).collect(); - files.sort(); - let file0 = &files[0]; - let file1 = &files[1]; - println!("{} {}", file0, file1); - assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib")); - assert!(file0.ends_with(env::consts::DLL_SUFFIX) || - file1.ends_with(env::consts::DLL_SUFFIX)); + assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file()); + let fname = format!("{}foo{}", env::consts::DLL_PREFIX, + env::consts::DLL_SUFFIX); + assert_that(&p.root().join("target/debug").join(&fname), existing_file()); }); test!(unused_keys { diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index 01011e5b4..3d90bd106 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -218,7 +218,9 @@ test!(doctest_a_plugin { name = "bar" plugin = true "#) - .file("bar/src/lib.rs", ""); + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 876cd8d58..91304272a 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -164,6 +164,8 @@ test!(many_similar_names { }); test!(cargo_test_failing_test { + if !::can_panic() { return } + let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) .file("src/foo.rs", r#" @@ -690,7 +692,7 @@ test!(bin_there_for_integration { authors = [] "#) .file("src/main.rs", " - fn main() { panic!(); } + fn main() { std::process::exit(101); } #[test] fn main_test() {} ") .file("tests/foo.rs", r#" diff --git a/tests/tests.rs b/tests/tests.rs index 6aba35471..b82c2ecf5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -65,3 +65,8 @@ fn is_nightly() -> bool { let version_info = cargo::ops::rustc_version("rustc").unwrap().0; version_info.contains("-nightly") || version_info.contains("-dev") } + +fn can_panic() -> bool { + let host = cargo::ops::rustc_version("rustc").unwrap().1; + !host.contains("msvc") +} -- 2.30.2